package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.CurCourseType;
import com.macro.mall.portal.service.CurCourseTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程类型表(cur_course_type）
 *
 * @author gaodx
 * @create 2020-08-11 15:43
 **/
@Slf4j
@RestController
@RequestMapping("curCourseType")
@Api(tags = "CurCourseTypeController", description = "业务范围管理(cur_course_type）")
public class CurCourseTypeController {

    @Autowired
    CurCourseTypeService curCourseTypeService;

    @ApiOperation("查询业务范围")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<CurCourseType>> list(@RequestParam(value = "id", required = false) Integer id) {
        CurCourseType build = CurCourseType.builder().id(id).build();
        List<CurCourseType> curCourseTypes = curCourseTypeService.selectAllByCurCourseType(build);
        return CommonResult.success(CommonPage.restPage(curCourseTypes));
    }

    @ApiOperation("父节点查询业务范围")
    @RequestMapping(value = "/listByParentId", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<CurCourseType>> listByParentId(@RequestParam(value = "parentId", required = false) Integer parentId) {
        CurCourseType curCourseType = new CurCourseType();
        curCourseType.setParentId(parentId);
        List<CurCourseType> curCourseTypes = curCourseTypeService.selectAllByParentId(curCourseType);
        return CommonResult.success(CommonPage.restPage(curCourseTypes));
    }


}